package com.code.controller;

import com.alibaba.fastjson.JSONObject;
import com.code.domain.CommonResult;
import com.code.domain.PageObject;
import com.code.entity.Area;
import com.code.feign.AreaFeign;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 通过openfeign 进行区块的调用
 */
@Slf4j
@Controller
@ApiOperation(value = "区块模块",notes = "区块模块")
@RequestMapping("/areaFeign")
public class AreaFeignController {

    @Autowired
    @Lazy
    private AreaFeign areaFeign;

    @GetMapping(value = "/to/toAreaIndex")
    @ApiOperation(value = "跳转区域",notes = "跳转区域")
    public String toAreaIndex(Model model, HttpServletRequest request, HttpServletResponse response){
        return "area/area_index";
    }

    @ApiOperation(value = "获取area数据",notes = "获取area数据")
    @GetMapping(value = "/queryAreaLayUiPage")
    public @ResponseBody
    CommonResult queryAreaLayUiPage( Area area, HttpServletRequest request, HttpServletResponse response){
       String listStr =  areaFeign.queryAreaLayUiPage(area);
        JSONObject jsonObject = JSONObject.parseObject(listStr);
        if(jsonObject.get("data") != null ){
            return new CommonResult(0,"操作成功",Integer.parseInt(jsonObject.get("count").toString()),jsonObject.get("data"));
        }else{
            return new CommonResult(0,"操作成功",0,null);
        }
    }





}
